/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package week4.Opdracht1;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

/**
 *
 * @author 0833809
 */
public class transfomer {

    public static void main(String[] args)
            throws TransformerException, TransformerConfigurationException,
            FileNotFoundException, IOException {
        // create a transformer factory and set properties on it
        TransformerFactory factory = TransformerFactory.newInstance();

        // once you've configured the factory create you transformer giving it the stylesheet
        Transformer transformer = factory.newTransformer(new StreamSource("H:\\Mijn Documenten\\NetBeansProjects\\trunk\\infswa01\\src\\week3_xlst\\Opdracht3\\XSLT Script.xml"));

        // then perform the transform on 'foo.xml' and dump it to System.out
        transformer.transform(new StreamSource("H:\\Mijn Documenten\\NetBeansProjects\\trunk\\infswa01\\src\\week3_xlst\\Opdracht3\\XSLT Script.xml"), new StreamResult(System.out));
    }

    public String toonXSLTString(String xmlpad, String xsltpad) {
        String bericht = "";
        File stylesheet = new File(xsltpad);
        StringWriter output = new StringWriter();

        try {
            StreamSource stylesource = new StreamSource(stylesheet);

            TransformerFactory tf = TransformerFactory.newInstance();
            Templates cachedXSLT = tf.newTemplates(stylesource);
            Transformer transformer = cachedXSLT.newTransformer();

            // StringWriter output=new StringWriter();


            String str = "";
            Source requestxml = new StreamSource(xmlpad);
            Result response = new StreamResult(output);


//   Result responseString = new StreamResult(str);
            transformer.transform(requestxml, response);

        } catch (TransformerException e) {
            System.err.println(e);
            bericht += e;
        }
        return output.toString();
    }
}
